from pprint import pprint

from selenium import webdriver
# 打开浏览器
driver = webdriver.Chrome()
driver.get("https://www.baidu.com")
driver.maximize_window()
# 操作cookie
# 获取所有的cookie信息 语法:driver.get_cookies()
print(driver.get_cookies())
# print(driver.get_cookie(name))返回特定的name的cookie信息
print(driver.get_cookie('PTOKEN_BFESS'))

# 添加操作 语法:driver.add_cookie(cookie_dict)添加cookie,必须有name和value值
# dict1 = {'name': 'hello', 'value': '123'}
# driver.add_cookie(dict1)
# pprint(driver.get_cookies())
# 删除特定(部分)的cookie信息  语法:driver.delete_cookie(name)
# print(driver.delete_cookie('hello'))
pprint(driver.get_cookie('hello'))

# 删除所有的cookie信息 语法:driver.delete_all_cookies()
driver.delete_all_cookies()
pprint(driver.get_cookies())

# 关闭浏览器
driver.quit()